Part Number Hot Search : 
PD121XL4 087TR SLLB120 TLPGU50T H30A04 MM5Z36H AD7675 MRB32W
Product Description
Full Text Search
 

To Download AN2841 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  november 2008 rev 1 1/31 AN2841 application note led dimming implemented on stm32? microcontroller 1 introduction this application note deals with the general principles of led dimming. this note also focuses on the use of pulse width modulation (pwm) for digital dimming. its implementation on the stm32 ? microcontroller in combination with the stp24dp05 led driver is described in detail and the most common design approaches are compared. the conclusion helps developers choose the best approach for their led dimming application. www.st.com
contents AN2841 2/31 contents 1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 description of led dimming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1 driving multiple led applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.2 multi-channel dimming using serial-parallel conversion . . . . . . . . . . . . . . . 6 2.3 specific dimming application using an stp24dp05 . . . . . . . . . . . . . . . . . 8 3 dimming application using an stm32 microcontroller . . . . . . . . . . . . . 9 3.1 data transfers and timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.1.1 dynamic data transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.1.2 static data transfer using lookup tables . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.1.3 single interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.1.4 single interrupt with dma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.1.5 interrupt + dma + interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.2 data preparation: redundant and non redundant use of memory . . . . . . 19 3.2.1 full lookup table (redundant) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.2.2 reduced lookup table (non redundant) . . . . . . . . . . . . . . . . . . . . . . . . . 20 3.3 timing: set up of the main dimming timer . . . . . . . . . . . . . . . . . . . . . . . . 22 3.3.1 the main system timer, systick setting . . . . . . . . . . . . . . . . . . . . . . . . 22 4 achieved values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 4.1 dimming approach comparison and conclusion . . . . . . . . . . . . . . . . . . . 29 4.1.1 comparison between interrupt and interrupt + dma approaches . . . . . 29 4.1.2 comparison between dynamic preparation, static, and reduced static lookup table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 5 references documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 6 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
AN2841 list of tables 3/31 list of tables table 1. ledmap - requested led brightness configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 table 2. full lookup table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 table 3. ledmap - requested led brightness configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 table 4. ledmap - reordered requested led brightness configuration . . . . . . . . . . . . . . . . . . . . . . 22 table 5. reduced lookup table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 table 6. totaltime necessary for requested dimming parameters. . . . . . . . . . . . . . . . . . . . . . . . . . 23 table 7. maximum refresh rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 table 8. systick-reload-time for 100 hz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 table 9. example of values used in equations 3 and 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 table 10. lookup table size (full and reduced) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 table 11. refresh frequencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 table 12. refresh frequencies for better optimized code (8 and 12-bit pwm) . . . . . . . . . . . . . . . . . . 28 table 13. refresh frequencies for better optimized code (10 and 11-bit pwm) . . . . . . . . . . . . . . . . . 28 table 14. document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
list of figures AN2841 4/31 list of figures figure 1. pwm signal with 16 steps of possible voltage values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 figure 2. pwm serial-parallel conversion for multiple led applications . . . . . . . . . . . . . . . . . . . . . . . 7 figure 3. example of a specific lighting setting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 figure 4. simplified setup of an application using an stp24dp05 . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 figure 5. stm32 evaluation board setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 figure 6. stm32 evaluation board block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 figure 7. computation of leddriverdatabuffer variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 figure 8. conversion of ledmap array to leddriverdatabuffer . . . . . . . . . . . . . . . . . . . . . . . . 11 figure 9. dynamic data preparation - time consumption - block diagram . . . . . . . . . . . . . . . . . . . . . 12 figure 10. dynamic data preparation - time consumption - real signals . . . . . . . . . . . . . . . . . . . . . . . 12 figure 11. static lookup table time consumption with 166 khz - 333 khz le signal . . . . . . . . . . . . . . 13 figure 12. timing diagram: single interrupt method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 4 figure 13. real timing signals for single interrupt method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 figure 14. timing diagram: single interrupt with dma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 figure 15. timer interrupt + dma transfer + dma interrupt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 figure 16. real signals: timer interrupt + dma transfer + dma interrupt model . . . . . . . . . . . . . . . . . 18
AN2841 description of led dimming 5/31 2 description of led dimming there are two categories of led dimming: analog: uses a linear device to set the current flow through the led. advantages: absence of digital noise; a simple implementation. limitations: color shift, low dynamics. digital: uses a switch to set nominal or zero current flow through the led. advantages: accurate and fast color control. limitations: the presence of digital noise and necessity to use a frequency high enough to prevent flickering; a complex implementation. this document focuses on digital dimming and the use of pwm (pulse width modulation) in common applications. when using pwm for lighting applications, the following rules must be kept in mind: for the led light to be seen as non-flickering by the human eye, in most cases the pwm frequency must be higher than 100 hz. the led light brightness depends on the pwm duty cycle. the brightness depends on the resolution of the pwm duty cycle. figure 1. pwm signal with 16 steps of possible voltage values using a 4-bit pwm resolution, there can be 16 different light intensity (energy) values. concerning color applications, 16 million (256 256 256) colors can be reached using tricolor leds with an 8-bit dimming resolution for each single color led. step: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 ... t pwm am00341
description of led dimming AN2841 6/31 2.1 driving multiple led applications displays, indicators and panels increasingly use more and more leds. there are three approaches for driving higher numbers of leds: 1. dedicated pin each led is driven by dedicated system (microcontroller, fpga) pin. advantages: simple implementation of dimming algorithm. no conversion. disadvantages: unusable for high led counts. consumes pins of microcontroller. 2. serial-parallel conversion multiple leds are driven by a single system pin. advantages: reduced number of system pins required. high led count systems can be developed. disadvantages: additional components and external buffers are needed. the data rate on a single pin must be n times greater than that for the single led out of n, where n is th e number of leds. 3. matrix leds are arranged in a square matrix and driven by a complex and sophisticated algorithm that combines serial-parallel conversion with additional decomposition of the serial data stream into the rows and columns by another active component. this document focuses on serial-parallel conversion applications. 2.2 multi-channel dimming using serial-parallel conversion the serial-parallel conversion approach is in fact a parallel-serial-parallel conversion since the data is stored in the system memory in parallel format and then is converted to serial format before its transfer over the serial interface. the serial stream is then reconverted to parallel format by the led driver used to drive each led. the serial data transfer speed must be n times faster than driving a single led, where n is the number of parallel driver outputs. buffers (led drivers) used for serial-parallel conversion come generally with the four most important signals: sdi: serial data in sdo: serial data out clk: clock signal used for loading data in the driver buffer via the sdi (input) and sending data from the buffer via the sdo (output). it also shifts all data actually present (previously loaded) in the driver. le: copies (latch enable) the actual values loaded in the driver into its output cells. the output cells drive parallel outputs. the standard serial peripheral interface (spi) contains sdo, sdi and clk signals. it is necessary to latch (le signal pulse) internal driver data once per n clk cycles, where n is the total led count. this latching rule ensures the correct mapping of the serialized pwm data coming on sdi to the corresponding parallel output. refer to figure 2 , figure 3 and figure 4 .
AN2841 description of led dimming 7/31 figure 2. pwm serial-parallel conversion for multiple led applications figure 3. example of a specific lighting setting the following equation is used to determine how many leds can used in an application with specific maximum spi speed and pwm resolution requirements: equation 1 where; n is the maximum number of leds f spi is the spi communication speed n is the pwm resolution f pwm is the dimming frequency serial data output 1 - ( l e d 1 ) output 2 - ( l e d 2 ) output 3 - ( l e d 3 ) output 4 - ( l e d 4 ) 1111 t t t t t 4% duty cycle 14% duty cycle 3% duty cycle 99% duty cycle levels t pwm 1101 0101 0001 0000 1111 or new data t send_data parallel data am00343 pwm n spi f f n 2 =
description of led dimming AN2841 8/31 the outcome of equation 1 is valid only for the best-case scenario when the data are sent to the led driver without any delay between blocks of data. this example, of course, is not a real one. the values for a real application can only get close to the value determined above. 2.3 specific dimming application using an stp24dp05 figure 4 illustrates a simple dimming application using an stp24dp05 24-bit constant current led sink driver with output error detection. figure 4. simplified setup of an application using an stp24dp05 driving system stp24dp05 r1...8 g1...8 b1...8 spi more drivers in cascade? rgb led configuration led block 3.3 v temperature sensor spi oe-r/g/b stp24dp05 le 5 v am00344
AN2841 dimming application using an stm32 microcontroller 9/31 3 dimming application using an stm32 microcontroller this section describes a dimming application that uses an stm32 microcontroller (mcu). all the computations, results and tests were performed on an evaluation board (reference: steval-ill015v1) containing an stm32 mcu running at a clock frequency of 48 mhz. for more information about the use of this evaluation board and dimming applications, please refer to user manuals um0588 and um0574 listed in section 5: references documents . figure 5 and figure 6 provide a brief overview of the stm32 evaluation board. figure 5. stm32 evaluation board setup figure 6. stm32 evaluation board block diagram 3.1 data transfers and timing this section describes the two approaches used to transfer data (dynamic and static) as well as timing considerations. 3.1.1 dynamic data transfer when using a dynamic data approach, all data is computed just before being transfered to the led drivers. usb spi spi spi power supply st1s10 esd for usb usbuf01p6 stm32 led driver stp24dp05 led driver stp24dp05 am00345
dimming application using an stm32 microcontroller AN2841 10/31 the led brightness value is defined by the user in the ledmap array. the ledmap is an array of 8-bit numbers (when using an 8-bit dimming resolution). each value is dedicated to one single led ( figure 7 ). the dimming algorithm converts the ledmap array into a serial stream. the serial stream in combination with the le signal generates requested pwm outputs on the led drivers as shown in figure 8 . figure 7. computation of leddriverdatabuffer variable am00346 depth = 0 datachar = 0 datachar++ detail in figure 8: ledmap leddriverdatabuffer depth++ led driver spi 0 .. 255 for 8-bit pwm resolution 0 .. ledcount / 8 ? ? + + datachar>3 depth>255 begin
AN2841 dimming application using an stm32 microcontroller 11/31 figure 8. conversion of ledmap array to leddriverdatabuffer example using a 48 led matrix with an 8-bit pwm resolution while(1) for(depth = 1; depth<=0xff; depth++){ for(datachar = 0; datachar < 4; datachar++){ for(outputbit = 0; outputbit < 8; outputbit++){ leddriverdatabuffer[datachar] <<= 1; if(ledmap[(datachar*8) + outputbit] > depth) leddriverdatabuffer[datachar] |= 0x0001; else leddriverdatabuffer[datachar] &= 0xfffe; } spi_senddata(spi1, leddriverdatabuffer[datachar]); } le_low(); le_high(); le_low(); } even though the dynamic data preparation consumes a minimum of system memory, it takes a lot of computational time. this approach is only recommended for low led count applications. a dynamic data preparation approach can reach 100 hz for 32 leds (with maximum code optimization in c compiler on the stm32 evaluation board). ledmap[0] > depth = 0 ledmap[1] > depth = 1 ledmap[2] > depth = 1 ledmap[3] > depth = 0 ledmap[4] > depth = 1 ledmap[6] > depth = 1 ledmap[7] > depth = 0 ledmap[8] > depth = 0 for one time stamp depth = 50 ledmap = { 20, 60, 75, 22, 100, 255, 0, 5} leddriverdatabuffer[0] led driver for outputbit from 0 to 7 spi am00347
dimming application using an stm32 microcontroller AN2841 12/31 figure 9. dynamic data preparation - time consumption - block diagram figure 10. dynamic data preparation - time consumption - real signals 3.1.2 static data transfer using lookup tables when using static lookup tables, all data is computed before being sent to the led drivers. static lookup tables are used to convert the brightness value from an 8-, 9-, 10-, 11- or 12-bit representation from the ledmap array into the serial stream representing the pwm of the led driver outputs.
AN2841 dimming application using an stm32 microcontroller 13/31 once the brightness data is determined, the repetitive dimming procedure needs only to take the prepared data and send it to the led driver. figure 11 shows the calculation time of the algorithm. figure 11. static lookup table time consumption with 166 khz - 333 khz le signal accurate le timing and the dimming part running in the application background are necessary requirements for a successful application. these targets can be achieved using the following methods: single interrupt single interrupt with dma interrupt + dma + interrupt 3.1.3 single interrupt the simplest approach is to use a timer interrupt approach where only a timer interrupt is required for the data transfer timing. this approach which does not require direct memory access (dma) is designed for microcontrollers without dma capability. except for pattern loading, spi data transfer and latch enable generation, the code must also contain the tx buffer empty flag test. this test must be taken into account if you compute the total time necessary for all dimming operations.
dimming application using an stm32 microcontroller AN2841 14/31 figure 12 shows a timing diagram for a dimming application using this method. figure 12. timing diagram: single interrupt method figure 13 shows the waveforms of the signals output by the mcus controlling the led drivers. figure 13. real timing signals for single interrupt method
AN2841 dimming application using an stm32 microcontroller 15/31 example of c code implementation of the timer interrupt routine void systickhandler(void) { le_low(); (step 1) le_high(); depth+=4; if(depth > 0x400) (step 2) depth = 0; spi_senddata(spi1, lookup[depth+0]); (step 3) while(!spi_getflagstatus(spi1, spi_flag_txe)); spi_senddata(spi1, lookup[depth+1]); while(!spi_getflagstatus(spi1, spi_flag_txe)); (step 4) spi_senddata(spi1, lookup[depth+2]); while(!spi_getflagstatus(spi1, spi_flag_txe)); spi_senddata(spi1, lookup[depth+3]); while(!spi_getflagstatus(spi1, spi_flag_txe)); le_low(); (step 5) le_high(); } in the above example, the waveform and program code are described in the following steps: 1. the generation of the le after entering the interrupt. 2. increment of the lookup table pointer. 3. the transfer of the first 8 bits. 4. test of tx buffer empty flag. 5. an additional edge on le. this is for measurement purposes only. 6. the time between the end of the current interrupt and the next one. this time can be used for calculating certain fo reground tasks in the application.
dimming application using an stm32 microcontroller AN2841 16/31 3.1.4 single interrupt with dma the data is transferred from the microcontroller ram into the led driver using a single interrupt with dma approach. you cannot use a dma approach without a timer, because you cannot change the speed of the dma and thus you cannot change pwm parameters and the refresh rate in required steps. the benefit of using dma is that the spi buffer can be automatically filled. the time saved is nearly in the range of the time needed for the dma to restart and re-configure itself for the next transfer (in comparison to previous approach). an example of a timing diagram for this programming model is shown in figure 14 . the timing can be compared in figure 12 and figure 14 . figure 14. timing diagram: single interrupt with dma
AN2841 dimming application using an stm32 microcontroller 17/31 3.1.5 interrupt + dma + interrupt figure 14 shows that data from the previous transfer is latched during the current timer interrupt which causes several problems. the algorithm is more complicated in this case. a slightly different approach that has no impact on the system can be used: it is obtained by generating the le pulse when the dma transfer is complete instead of generating it on a timer interrupt. the le pulse is generated at the dma transfer complete interrupt as shown in figure 15 . figure 15. timer interrupt + dma transfer + dma interrupt figure 16 shows the waveform of the outbound signals from the microcontrollers controlling the led drivers. an example of the c code implementation of the timer routine is given below. a detailed description follows the example.
dimming application using an stm32 microcontroller AN2841 18/31 figure 16. real signals: timer interrupt + dma transfer + dma interrupt model step "1" in figure 16 is not necessary, but it is used for a better visualization of the tracking of signals on the oscilloscope. example of c code of dma and timer interrupt routine: interrupt + dma + interrupt approach void systickhandler(void) { le_low(); (step 1) le_high(); depth+=4; if(depth > 0x400) depth = 0; dma_channel3->ccr &= ccr_enable_reset; dma_channel3->cndtr = 0x04; dma_channel3->cmar = ((u32) (lookup))+depth; dma_channel3->ccr |= ccr_enable_set; (step 2) dma_channel3->ccr |= dma_it_tc; le_low(); } void dmachannel3_irqhandler(void) (step 5) { while(!spi_getflagstatus(spi1, spi_flag_txe)); (step 6) le_high(); (step 7) le_low(); dma_clearitpendingbit(dma_it_gl3); }
AN2841 dimming application using an stm32 microcontroller 19/31 in the above example, the waveform and program code are described in the following steps: 1. the generation of the le after entering the interrupt. 2. setting the dma: source address, data length, and start flag. 3. data is sent automatically by dma. 4. data is sent automatically by dma. 5. dma interrupt routine is called when the last byte is sent by dma. 6. wait until the data from the spi tx buffer is delivered to the driver. (step 6 can be exchanged with calculations that take the amount of time necessary for the spi transfer to be finished). 7. le generation. 3.2 data preparation: redundant and non redundant use of memory 3.2.1 full lookup table (redundant) the static lookup table generation is mentioned in section 3.1.2 . the lookup table generation procedure is described in more detail in this section. the lookup table row is computed for every pwm step (8-bit pwm means 256 rows for 256 steps). the c code of the full lookup table generation is given in the example below. example using a 48 led matrix with an 8-bit pwm resolution void generatelookuptable(unsigned char *ledmapin){ unsigned int tmpdepth; for(tmpdepth = 0; tmpdepth < 0xff; tmpdepth++){ for(datachar = 0; datachar < 4; datachar++){ for(outputbit = 0; outputbit < 8; outputbit++){ lookup[tmpdepth*4 + datachar] <<= 1; if(ledmapin[(datachar*8) + outputbit] > tmpdepth) lookup[tmpdepth*4 + datachar] |= 0x01; else lookup[tmpdepth*4 + datachar] &= 0xfe; } } } } table 1. ledmap - requested led brightness configuration output led 1 led 2 led 3 ? ? led i duty cycle (brightness) 2 / 2 n 6 / 2 n 4 / 2 n 100%
dimming application using an stm32 microcontroller AN2841 20/31 3.2.2 reduced lookup table (non redundant) only the data that changes the led driver output state is generated. a led can change the state only once per complete pwm cycle: from one to zero. if there are i number of leds, there are i new data items for the led drivers. for example, if i = 32 leds when using an 8-bit pwm, you need a cycle with i i = 32 32 = 1024 loops. the inside of the loop is the same for full lookup table generation as described in section 3.2.1 . the lookup table row is computed only in case you need to change the led intensity pattern (specific value of a parallel output configuration). ta ble 3 , ta bl e 4 and ta b l e 5 bring better understanding of the lookup table reduction. the c code of the reduced lookup table generation is shown in the example below. table 2. full lookup table step output led 1 led 2 led 3 ? ? led i 0 111 1 1 111 1 2 111 1 3 011 1 4 011 1 5 010 1 6 010 1 ? 000 1 ? 000 1 2 n 000 1
AN2841 dimming application using an stm32 microcontroller 21/31 example of reduced lookup table generation void performgeneratereducedlookuptable(unsigned char *ledmapin, int ledcount, int pwmdepth, unsigned char **tablein, unsigned char **tablekeyin, int *table_size){ int streamsize = ledcount/8; *table_size = differentvaluescount(ledmapin, ledcount); *tablekeyin = sortandreduce(ledmapin, ledcount, *table_size); *tablein = malloc(streamsize * (*table_size) * sizeof(unsigned char)); for(tmpdepth = 0; tmpdepth < (*table_size); tmpdepth++){ for(datachar = 0; datachar < streamsize; datachar++){ for(outputbit = 0; outputbit < 8; outputbit++){ (*tablein)[tmpdepth*streamsize + datachar] <<= 1; if(ledmapin[(datachar*8) + outputbit] > (*tablekeyin)[tmpdepth]) (*tablein)[tmpdepth*streamsize + datachar] |= 0x01; else (*tablein)[tmpdepth*streamsize + datachar] &= 0xfe; } } } } . table 3. ledmap - requested led brightness configuration outputs led 1 led 2 led 3 ? ? led i duty cycle (brightness) 2 / 2 n 6 / 2 n 4 / 2 n 100%
dimming application using an stm32 microcontroller AN2841 22/31 3.3 timing: set up of the main dimming timer 3.3.1 the main system timer, systick setting the approach with interrupt + dma + interrupt is considered the most effective. the microcontroller can reach the maximum frame rate based on the minimum time required for the all the necessary operations. a time reserve of 6% was used: t dmaen re-enabling the dma (~ 1.25 s) t onespi time necessary for transfer of the data over spi (~ leds 55 ns) t legen le generation and new data pointer generation (~ 1 s) the total time needed for correct processing is the sum of the times above: equation 2 totaltime = t dmaen + t onespi leds + t legen = 1.25 s + 55 ns leds + 1 s = 2.25 s + 55 ns leds the number of leds must be rounded up to nearest number commensurable by the length of an spi buffer. the spi buffer length is 8 either or 16 bits in most cases. table 4. ledmap - reordered requested led brightness configuration output led 1 led 3 led 2 ? led x led i duty cycle (brightness) 2 / 2 n 4 / 2 n 6 / 2 n / 2 n 100% step of change (time of change) 2 4 6 100% table row 123 i table 5. reduced lookup table row level output led 1 led 2 led 3 ? ? led i 00 111111 12 111111 24 011111 36 010111 ?? 000111 ?? 000011 m (1) 1. " m " is less or equal to number of leds = i x + 1 000001
AN2841 dimming application using an stm32 microcontroller 23/31 more examples of totaltime for different number of leds and pwm resolution can be seen in ta bl e 6 . ta b l e 6 shows the time required for processing one pwm step, one buffer load and one buffer latch. with an 8-bit pwm resolution, 256 buffer latches are needed; the maximum le (latch enable) frequency must be divided by 256. these results are shown in ta ble 7 . . ta b l e 7 shows the maximum refresh frequencies for controlled leds. but the inverse computation must be used to solve our task. ta bl e 8 shows the inversion of the table 7 values and gives the required refresh frequency. the le frequency must be derived and the systick timer preload value (systick-preload-value) set to generate the le pulse by generating an interrupt at every counter reload event. ta b l e 7 and ta ble 8 show that systick-reload-frequency will be set between 25.6 khz and 371.7 khz according to requested pwm resolution and led count. the stm32 systick timer uses a reference clock of 72 mhz when set to the maximum value. the interrupt period for this timer is the systick-preload-value multiplied by 1 / (72 000 000). the reference clock of stm32 evaluation board is set to 48 mhz for the usb to operate correctly. this value should be taken into the account while making measurements on this evaluation board as their computation will influence equation 3 . the reference clock can be also divided by 8 by using the hardware divider. the divided reference clock is then 9 mhz. in this case, the interrupt period for this timer is equal to a preload value multiplied by 1 / (9 000 000). preload value = requested systick interrupt time / reference period preload value = reference frequency / requested systick interrupt frequency. table 6. totaltime necessary for requested dimming parameters leds pwm totaltime max. le frequency 8 8-bit 2.25 + 0.055 8 = 2.69 s 371.7 khz 8 12-bit 2.25 + 0.055 8 = 2.69 s 371.7 khz 672 8-bit 2.25 + 0.055 672 = 39.21 s 25.5 khz table 7. maximum refresh rate leds pwm max. le frequency max. refresh rate 8 8-bit 371.7 khz 1452 hz 8 12-bit 371.7 khz 90.7 hz 672 8-bit 25.5 khz 99.6 hz table 8. systick-reload-time for 100 hz leds pwm requested refresh rate systick-reload-time 8 8-bit 100 hz 39 s (25.6 khz) 8 12-bit 90.7 hz 2.7 s (371.7 khz) 672 8-bit 100 hz 39 s (25.6 khz) 32 8-bit 100 hz 39 s (25.6 khz)
dimming application using an stm32 microcontroller AN2841 24/31 equation 3 systick-preload-value = 72 000 000 / 25 600 = 2812 the frequency ranges 25.6 khz and 371.7 khz required for all possible applications ranges can be achieved using preload values: 2812 and 194, or with divider by 8: 351 or 24. systick timer setting with no divider on the reference clock: systick_clksourceconfig(systick_clksource_hclk); systick_setreload(900); generates pulses with the period of 12 s. systick timer setting with the divider by 8 on the reference clock: systick_clksourceconfig(systick_clksource_hclk_div8); systick_setreload(900); generates pulses with the period of 100 s. the setup algorithm for the systick timer configuration has to check if it is possible to set preload value to keep enough time for processing (totaltime) together with reaching the requested refresh frequency: totaltime = 2.25 + 0.055 leds systick-reload-time = 1 / systick-reload-frequency totaltime is the time slot, during which the spi transfer and all the arbitrations needs to be achieved. the systick time is the time slot which must be respected to reach the required refresh rate. equation 4 systick-reload-time > totaltime to reach the requested refresh rate and set up the systick timer preload value: systick-reload-frequency = requested-refresh-rate pwmdepth (100 hz 256 steps). table 9. example of values used in equations 3 and 4 leds pwm requested refresh rate systick -reload-time 32 8-bit 100 hz 39 s (25.6 khz)
AN2841 achieved values 25/31 4 achieved values dynamic computing takes a lot of time and 120 hz can be reached only for 32 leds. in addition, no other foreground or background tasks can be perform ed during computation. as a consequence, this solution is recommended only for simple applications that use only a few diodes. for other more complicated applications, it is recommended to use the lookup table approach using a single interrupt only or interrupt + dma (if dma is available). the led brightness resolution is limited by the size of the lookup table ( ta b l e 1 0 ). for every level of brightness, you need a single string of zeros and ones for all the leds. from figure 13 , the maximum refresh frequency can be computed. the time between two interrupts is 6 s. this is a refresh rate for one brightness level, for 32 leds, 166 khz. ta b l e 1 1 . shows the possible refresh rates for whole brightness depth and different led count. table 10. lookup table size (full and reduced) bit depth leds lookup table size: i 2 n reduced table size (1) : i n 1. values indicates the maximum size. 832 256 4 = 1 kb 32 4 = 128 b 12 32 4096 4 = 16 kb 32 4 = 128 b 8 128 256 16 = 4 kb 128 16 = 2 kb 12 128 4096 16 = 64 kb 128 16 = 2 kb 8 512 256 64 = 16 kb 256 64 = 16 kb 12 512 4096 64 = 256 kb 512 64 = 32 kb
achieved values AN2841 26/31 table 11. refresh frequencies leds/pwm 8-bit [hz] 9-bit [hz] 10-bit [hz] 11-bit [hz] 12-bit [hz] 256 512 1024 2048 4096 8 1514 757 379 189 95 (1) 16 1293 647 323 162 81 24 1129 564 282 141 71 32 1002 501 250 125 63 40 900 450 225 113 56 48 817 409 204 102 51 56 748 374 187 94 47 64 690 345 173 86 43 72 640 320 160 80 40 80 597 299 149 75 37 88 560 280 140 70 35 96 526 263 132 66 33 104 497 248 124 62 31 112 471 235 118 59 29 120 447 223 112 56 28 128 426 213 106 53 27 136 406 203 102 51 25 144 388 194 97 49 24 152 372 186 93 47 23 160 357 179 89 45 22 168 343 172 86 43 21 176 330 165 83 41 21 184 319 159 80 40 20 192 308 154 77 38 19 7200 297 149 74 37 19 208 288 144 72 36 18 216 279 139 70 35 17 224 270 135 68 34 17 232 262 131 66 33 16 240 255 127 64 32 16 248 248 124 62 31 15 256 241 120 60 30 15 264 234 117 59 29 15
AN2841 achieved values 27/31 272 228 114 57 29 14 280 223 111 56 28 14 288 217 109 54 27 14 296 212 106 53 27 13 304 207 104 52 26 13 312 202 101 51 25 13 320 198 99 49 25 12 328 194 97 48 24 12 336 189 95 47 24 12 344 185 93 46 23 12 352 182 91 45 23 11 360 178 89 45 22 11 368 175 87 44 22 11 376 171 86 43 21 11 384 168 84 42 21 10 392 165 82 41 21 10 400 162 81 40 20 10 408 159 79 40 20 10 416 156 78 39 20 10 424 153 77 38 19 10 432 151 75 38 19 9 440 148 74 37 19 9 448 146 73 36 18 9 456 144 72 36 18 9 464 141 71 35 18 9 472 139 70 35 17 9 480 137 68 34 17 9 488 135 67 34 17 8 496 133 66 33 17 8 504 131 65 33 16 8 512 129 64 32 16 8 520 127 64 32 16 8 528 125 63 31 16 8 table 11. refresh frequencies (continued) leds/pwm 8-bit [hz] 9-bit [hz] 10-bit [hz] 11-bit [hz] 12-bit [hz] 256 512 1024 2048 4096
achieved values AN2841 28/31 536 124 62 31 15 8 544 122 61 30 15 8 552 120 60 30 15 8 560 119 59 30 15 7 568 117 59 29 15 7 576 116 58 29 14 7 584 114 57 29 14 7 592 113 56 28 14 7 600 111 56 28 14 7 608 110 55 27 14 7 616 110 55 27 14 7 624 110 55 27 14 7 632 106 53 26 13 7 640 105 52 26 13 7 648 103 52 26 13 6 656 102 51 26 13 6 664 101 51 25 13 6 672 100 50 25 12 6 680 99 49 25 12 6 688 98 49 24 12 6 1. 100 hz can be reached with very high level of optimization. table 12. refresh frequencies for better optimized code (8- and 12-bit pwm) leds 8-bit pwm freq. [hz] 12-bit pwm freq. [hz] 32 250 000 / 256 = 1000 250 000 / 4096 = 61 128 (250 000 / 256) / 4 = 244 (250 000 / 4096) / 4 = 15 512 (250 000 / 256) / 16 = 61 (250 000 / 4096) / 16 = 4 table 13. refresh frequencies for better optimized code (10- and 11-bit pwm) leds 10-bit pwm freq. [hz] 11-bit pwm freq. [hz] 32 250 000 / 1024 = 244 250 000 / 2048 = 122 128 (250 000 / 1024) / 4 = 64 (250 000 / 2048) / 4 = 30 512 (250 000 / 1024) /16 = 15 (250 000 / 2048) / 16 = 7 table 11. refresh frequencies (continued) leds/pwm 8-bit [hz] 9-bit [hz] 10-bit [hz] 11-bit [hz] 12-bit [hz] 256 512 1024 2048 4096
AN2841 achieved values 29/31 ta b l e 1 2 and ta ble 1 3 show the results in case you remove the additional le edge used for the measurement of the interrupt end and optimize time between two interrupts (used for spi in 16-bit mode). 4.1 dimming approach comparison and conclusion 4.1.1 comparison between interrupt and interrupt + dma approaches when using the single interrupt approach described in figure 12 and figure 13 , the time spent by the mcu to drive the leds is long and little time is left to execute other tasks. the combination of the single interrupt + dma approach frees more computing time for other tasks. this approach does not improve the refresh rate. 4.1.2 comparison between dynamic preparation, static, and reduced static lookup table the dynamic data preparation shown in figure 9 allows to save memory but requires additional computing time. the static lookup table method saves computing time. however, the computing must be performed at the beginning of the dimming. the reduced static lookup table offers the same functionalities as a full lookup table, while saving memory space.
references documents AN2841 30/31 5 references documents 1. user manual um0588 - multilayer c library for led dimming used on systems with spi and dma capabilities 2. user manual um0574 - steval-ill015v1 - led dimmer demonstration board based on the stp24dp05 and stm32?. 6 revision history table 14. document revision history date revision changes 10-nov-2008 1 initial release.
AN2841 31/31 please read carefully: information in this document is provided solely in connection with st products. stmicroelectronics nv and its subsidiaries (?st ?) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described he rein at an y time, without notice. all st products are sold pursuant to st?s terms and conditions of sale. purchasers are solely responsible for the choice, selection and use of the st products and services described herein, and st as sumes no liability whatsoever relating to the choice, selection or use of the st products and services described herein. no license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. i f any part of this document refers to any third party products or services it shall not be deemed a license grant by st for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoev er of such third party products or services or any intellectual property contained therein. unless otherwise set forth in st?s terms and conditions of sale st disclaims any express or implied warranty with respect to the use and/or sale of st products including without limitation implied warranties of merchantability, fitness for a particular purpose (and their equivalents under the laws of any jurisdiction), or infringement of any patent, copyright or other intellectual property right. unless expressly approved in writing by an authorized st representative, st products are not recommended, authorized or warranted for use in military, air craft, space, life saving, or life sustaining applications, nor in products or systems where failure or malfunction may result in personal injury, death, or severe property or environmental damage. st products which are not specified as "automotive grade" may only be used in automotive applications at user?s own risk. resale of st products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by st for the st product or service described herein and shall not create or extend in any manner whatsoev er, an y liability of st. st and the st logo are trademarks or registered trademarks of st in various countries. information in this document supersedes and replaces all information previously supplied. the st logo is a registered trademark of stmicroelectronics. all other names are the property of their respective owners. ? 2008 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - belgium - brazil - canada - china - czech republic - finland - france - germany - hong kong - india - israel - ital y - japan - malaysia - malta - morocco - singapore - spain - sweden - switzerland - united kingdom - united states of america www.st.com


▲Up To Search▲   

 
Price & Availability of AN2841

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X